package com.controller.user;

import com.dao.JobDao;
import com.dao.imp.JobDaoimpl;
import com.entity.FavouriteJob;
import com.entity.Resume;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/isFavouriteJob")
public class isFavouriteJob extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String jobId = req.getParameter("jobId");
        String userId = req.getParameter("userId");
        System.out.println("userId = " + userId);
        System.out.println("jobId = " + jobId);


        FavouriteJob favouriteJob = new FavouriteJob();

        favouriteJob.setJobId(Integer.parseInt(jobId));
        favouriteJob.setUserId(userId);

        JobDao jobDao = new JobDaoimpl();

        System.out.println("RemoveFavouriteJob = " + favouriteJob);
//        int i1 = companyDao.delJob(jobId);
        int i = 0;
        try {
//            i = jobDao.RemoveFavouriteJob(resume);
            i = jobDao.isFavouriteJob(favouriteJob);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        System.out.println("isFavouriteJob i = " + i);
        if(i==1){
            resp.getWriter().write("success");
        }else{
            resp.getWriter().write("fail");
        }

    }
}
